package com.example.administrator.yanfoxconn.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.RequiresApi;

import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.adapter.EmpListAdapter;
import com.example.administrator.yanfoxconn.bean.ActivityMsg;
import com.example.administrator.yanfoxconn.bean.EmpMessage;
import com.example.administrator.yanfoxconn.bean.JVSchoolInfo;
import com.example.administrator.yanfoxconn.constant.Constants;
import com.example.administrator.yanfoxconn.constant.FoxContext;
import com.example.administrator.yanfoxconn.utils.BaseActivity;
import com.example.administrator.yanfoxconn.utils.ChangeTextUtils;
import com.example.administrator.yanfoxconn.utils.FileUtil;
import com.example.administrator.yanfoxconn.utils.HttpConnectionUtil;
import com.example.administrator.yanfoxconn.utils.HttpUtils;
import com.example.administrator.yanfoxconn.utils.TimeDateUtils;
import com.example.administrator.yanfoxconn.utils.ToastUtils;
import com.example.administrator.yanfoxconn.widget.MyListView;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 人資校企合作發佈
 * Created by S1007989 on 2021/7/31.
 */

public class SchoolReleaseActivity extends BaseActivity implements View.OnClickListener,  DatePicker.OnDateChangedListener {
    private final int MESSAGE_NO_SCHOOL = 111;//m沒有對應學校
    private final int MESSAGE_SET_SCHOOL = 6;//賦值學校
    private final int MESSAGE_TOAST = 2;//掃描失敗彈出框
    private final int MESSAGE_UP = 3;//提交信息回復
    private final int MESSAGE_NETMISTAKE = 5;//網絡錯誤
    private final int MESSAGE_SET_BD = 7;//網絡錯誤
    private final int MESSAGE_SET_ZS = 8;//網絡錯誤
    private final int MESSAGE_SET_GET = 9;//網絡錯誤

    @BindView(R.id.btn_title_left)
    Button btnBack;//返回
    @BindView(R.id.tv_title)
    TextView tvTittle;//標題
    @BindView(R.id.btn_title_right)
    Button btnUp;//結束/提交
    DatePicker datePicker;
    @BindView(R.id.tv_c_code)
    TextView tvCCode;//对接窗口工号
    @BindView(R.id.tv_c_name)
    TextView tvCName;//对接窗口姓名
    @BindView(R.id.et_s_name)
    EditText etSName;//院校名称
    @BindView(R.id.lv_school)
    MyListView lvSchool;//院校列表
    @BindView(R.id.tr_list_school)
    TableRow trLIstSchool;//院校列表
    @BindView(R.id.tv_s_xian)
    TextView tvSXian;//院校线别
    @BindView(R.id.tv_date_c)
    TextView tvDateCome;//计划来烟日期
    @BindView(R.id.tv_date_r)
    TextView tvDateReturn;//计划返校日期
    @BindView(R.id.sp_plan)
    Spinner spPlan;//报到方式
    @BindView(R.id.et_person)
    EditText etPerson;//帶隊負責人
    @BindView(R.id.et_person_phone)
    EditText etPersonPhone;//帶隊負責人
    @BindView(R.id.rb_good_y)
    RadioButton rbGoodY;//行李是
    @BindView(R.id.rb_good_n)
    RadioButton rbGoodN;//行李否
    @BindView(R.id.rb_food_y)
    RadioButton rbFoodY;//餐包是
    @BindView(R.id.rb_food_n)
    RadioButton rbFoodN;//餐包否
    @BindView(R.id.sp_live)
    Spinner spLive;//住宿区域
    @BindView(R.id.tv_all_time)
    TextView tvAllTime;//实习时间
    @BindView(R.id.et_man)
    EditText etMan;//男
    @BindView(R.id.et_woman)
    EditText etWoman;//女
    @BindView(R.id.tv_people_num)
    TextView tvPeopleNum;//總數
    @BindView(R.id.et_t_man)
    EditText etTMan;//男
    @BindView(R.id.et_t_woman)
    EditText etTWoman;//女
    @BindView(R.id.tv_t_people_num)
    TextView tvTPeopleNum;//總數
    @BindView(R.id.et_get_id)
    EditText etGetId;//接待人工號
    @BindView(R.id.tv_get_name)
    TextView tvGetName;//接待人姓名
    @BindView(R.id.btn_search)
    Button btnSearch;//結束/提交
    @BindView(R.id.et_reason)
    EditText et_reason;//備註

    private String initStartDateTime; // 初始化开始时间
    private Date selectEndTime = null;//所選時間
    private Date curDate = null;//當前時間
    private String curDates;//當前時間
    private SimpleDateFormat formatter;
    private SchoolReleaseActivity mContext = this;
    private boolean b = true;
    private boolean isClicked = true;//判斷是否點擊
    private ActivityMsg activityMsg;
    private List<JVSchoolInfo> schoolLost,bdList,zsList;
    private EmpListAdapter mAdapter;
    private List<EmpMessage> empMessagesList;
    private String man="0",woman="0",tMan="0",tWoman="0",luggage="否",meal="否",way="",live="";
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_school_release);
        ButterKnife.bind(this);
        tvTittle.setText("校企合作計劃發佈");
        btnUp.setText("提交");
        btnUp.setVisibility(View.VISIBLE);
        btnUp.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        btnSearch.setOnClickListener(this);
        tvDateCome.setOnClickListener(this);
        tvDateReturn.setOnClickListener(this);
        rbFoodN.setChecked(true);
        rbGoodN.setChecked(true);
        rbFoodN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    meal="否";
                }else{
                    meal="是";
                }
            }
        });
        rbGoodN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    luggage="否";
                }else{
                    luggage="是";
                }
            }
        });
        tvCCode.setText(FoxContext.getInstance().getLoginId());
        tvCName.setText(FoxContext.getInstance().getName());
        getSchool();
        activityMsg = (ActivityMsg) getIntent().getSerializableExtra("item");
        formatter = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatterUse = new SimpleDateFormat("yyyy年MM月dd日");
        curDate = new Date(System.currentTimeMillis());
        //获取当前时间
        initStartDateTime = formatterUse.format(curDate);
        tvDateCome.setText(formatter.format(curDate));
        tvDateReturn.setText(formatter.format(curDate));
        curDates = formatter.format(curDate);
//        getMessage();
        etSName.setTag("0");
        date = new StringBuffer();

        //搜索关键字
        etSName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                trLIstSchool.setVisibility(View.VISIBLE);
                String a = etSName.getText().toString();
                //调用适配器里面的搜索方法
                mAdapter.SearchCity(ChangeTextUtils.simToTra(a));
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        etMan.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                if (etMan.getText().toString().equals("")){
                    tvPeopleNum.setText((Integer.parseInt(man)+Integer.parseInt(woman))+"");
                    etMan.setText("0");
                }else {
                    man = etMan.getText().toString();
                    tvPeopleNum.setText((Integer.parseInt(man) + Integer.parseInt(woman)) + "");
                }
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        etWoman.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (etWoman.getText().toString().equals("")){
                    tvPeopleNum.setText((Integer.parseInt(man)+Integer.parseInt(woman))+"");
                    etWoman.setText("0");
                }else {
                    woman = etWoman.getText().toString();
                    tvPeopleNum.setText((Integer.parseInt(man) + Integer.parseInt(woman)) + "");
                }
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        etTMan.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (etTMan.getText().toString().equals("")){
                    tvTPeopleNum.setText((Integer.parseInt(tMan)+Integer.parseInt(tWoman))+"");
                    etTMan.setText("0");
                }else {
                    tMan = etTMan.getText().toString();
                    tvTPeopleNum.setText((Integer.parseInt(tMan) + Integer.parseInt(tWoman)) + "");
                }
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        etTWoman.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (etTWoman.getText().toString().equals("")){
                    tvTPeopleNum.setText((Integer.parseInt(tMan)+Integer.parseInt(tWoman))+"");
                    etTWoman.setText("0");
                }else{
                tWoman = etTWoman.getText().toString();
                tvTPeopleNum.setText((Integer.parseInt(tMan)+Integer.parseInt(tWoman))+"");
                }
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        etGetId.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
              tvGetName.setText("");
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
    }
    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_title_left://返回
                finish();
                break;
            case R.id.btn_title_right://提交
                 check();
                break;
            case R.id.tv_date_c:
                initDateTime();
                show("start");
                break;
            case R.id.tv_date_r:
                initDateTime();
                show("end");
                break;
            case R.id.btn_search:
                getPeopleById(etGetId.getText().toString());
                break;
        }
    }

    Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {

                case Constants.MESSAGE_TOAST://Toast彈出
                   ToastUtils.showLong(SchoolReleaseActivity.this, msg.obj.toString());
//                    finish();
                    break;
                case MESSAGE_NO_SCHOOL://text賦值
                    ToastUtils.showLong(SchoolReleaseActivity.this, msg.obj.toString());
                    finish();
                    break;
                case Constants.MESSAGE_UP://提交響應
                    worningAlert(msg.obj.toString(),Constants.MESSAGE_TOAST);
//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());
                    break;
                case Constants.MESSAGE_ALERT://提交響應
                    worningAlert(msg.obj.toString(),Constants.MESSAGE_TOAST);
//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());
                    break;
                case MESSAGE_SET_SCHOOL:
                    setSchool();
                    getInfoBD("BD");
                    break;
                case MESSAGE_SET_BD:
                    setBD();
                    getInfoZS("ZS");
                    break;
                    case MESSAGE_SET_ZS:
                    setZS();
                    break;
                case MESSAGE_SET_GET:
                    tvGetName.setText(empMessagesList.get(0).getCHINESENAME());
                    break;
//                case MESSAGE_SHOW://顯示提醒
//                    setText();
//                    tvShow.setVisibility(View.VISIBLE);
//                    tvShow.setText(msg.obj.toString());
            }
            super.handleMessage(msg);
        }
    };
    //設置院校，及院線
    private void setSchool() {
        List<String> school = new ArrayList<>();
        for (int i = 0;i<schoolLost.size();i++){
            school.add(schoolLost.get(i).getS_NAME()+","+schoolLost.get(i).getS_ROAD());
        }
        mAdapter = new EmpListAdapter(SchoolReleaseActivity.this,school,"school");
        lvSchool.setAdapter(mAdapter);
        //稽核門崗列表,選中后1:tit賦值,2:列表隱藏
        mAdapter.OnClickSetText(new EmpListAdapter.OnClickSetText() {
            @Override
            public void OnClickxt(String tit) {
            }

            @Override
            public void OnClicktv(String tit, String tv) {

                etSName.setTag(tit);
                etSName.setText(tit);
                tvSXian.setText(tv);
                mAdapter.SearchCity("");
                trLIstSchool.setVisibility(View.GONE);
            }

        });
    }
    //提交前檢查
    private void check(){
        if(FoxContext.getInstance().getLoginId().equals("")){
            ToastUtils.showLong(mContext,"登錄超時,請退出重新登錄!");
            return;
        }

        if (etSName.getTag().toString().equals("0")){
            ToastUtils.showShort(mContext,"請選擇正確院校！");
            return;
        }
        if (etPerson.getText().toString().equals("")||etPersonPhone.getText().toString().equals("")){
            ToastUtils.showShort(mContext,"請輸入帶隊負責人完整信息！");
            return;
        }
        if (!tvAllTime.getText().toString().equals("")){
            if(Integer.parseInt(tvAllTime.getText().toString())<=0){
                ToastUtils.showShort(mContext,"請重新確認日期！");
                return;
            }
        }else{
                ToastUtils.showShort(mContext,"請選擇日期！");
                return;
        }
        if(etMan.getText().toString().equals("")){
            etMan.setText("0");
        }else if(etWoman.getText().toString().equals("")){
            etWoman.setText("0");
        }else if(etTMan.getText().toString().equals("")){
            etTMan.setText("0");
        }else if(etTWoman.getText().toString().equals("")){
            etTWoman.setText("0");
        }
        if (tvGetName.getText().toString().equals("")){
            ToastUtils.showShort(mContext,"請重新確認接待人！");
            return;
        }
        if (et_reason.getText().toString().equals("")){
            ToastUtils.showShort(mContext,"請輸入備註！");
            return;
        }
//        try {
//            selectEndTime = formatter.parse(tvDateReturn.getText().toString());
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        if (curDate.getTime()-selectEndTime.getTime()<0){
//            ToastUtils.showShort(mContext,"請检查活動結束時間！");
//            return;
//        }
        upMsessage();
    }

    //提交信息
    private void upMsessage() {

        final String url = Constants.HTTP_RZXQ_ADD_OK; //此處寫上自己的URL

        JsonObject object = new JsonObject();

//        object.addProperty("s_no","actEnd");
        object.addProperty("window_code",tvCCode.getText().toString());
        object.addProperty("window_name",tvCName.getText().toString());
        object.addProperty("school_name",etSName.getText().toString());
        object.addProperty("school_line",tvSXian.getText().toString());
        object.addProperty("p_date_come",tvDateCome.getText().toString());
        object.addProperty("p_date_return",tvDateReturn.getText().toString());
        object.addProperty("total_day", tvAllTime.getText().toString());
        object.addProperty("come_way",way);
        object.addProperty("leader_name",etPerson.getText().toString());
        object.addProperty("leader_tel",etPersonPhone.getText().toString());
        object.addProperty("luggage_flag",luggage);
        object.addProperty("mealbag_flag",meal);
        object.addProperty("dorm_area",live);
        object.addProperty("p_count_man",etMan.getText().toString());
        object.addProperty("p_count_woman", etWoman.getText().toString());
        object.addProperty("p_teacher_m",etTMan.getText().toString());
        object.addProperty("p_teacher_f",etTWoman.getText().toString());
        object.addProperty("receptionist_code",etGetId.getText().toString());
        object.addProperty("receptionist_name",tvGetName.getText().toString());
        object.addProperty("remark",et_reason.getText().toString());

        Log.e("----object----",  object.toString());

        //開啟一個新執行緒，向伺服器上傳資料
        new Thread() {
            public void run() {
                //把网络访问的代码放在这里
                try {
                    showDialog();
                    Log.e("-----url----",  url);
                    String result = HttpConnectionUtil.doPostJsonObject(url, object);
                    if (result != null) {
                        dismissDialog();
                        Log.e("----result-----",  result);
                        JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                        String errCode = jsonObject.get("errCode").getAsString();
                        if (errCode.equals("200")) {
                            Message message = new Message();
                            message.what = Constants.MESSAGE_ALERT;
                            message.obj = jsonObject.get("errMessage").getAsString();
                            mHandler.sendMessage(message);

                        } else{
                            Message message = new Message();
                            message.what = Constants.MESSAGE_ALERT;
                            message.obj = jsonObject.get("errMessage").getAsString();
                            mHandler.sendMessage(message);
                        }
                    }else{
                        Message message = new Message();
                        message.what = Constants.MESSAGE_NETMISTAKE;
                        mHandler.sendMessage(message);
                        finish();
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }finally {
                    FileUtil.deletePhotos(mContext);
                }
            }
        }.start();
    }

    private void aboutAlert(String msg, final int type) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("確認信息")
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton("確認", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
                        if (type==Constants.MESSAGE_TOAST){
                            finish();
                        }else if(type==Constants.MESSAGE_UP){
                            check();
                        }
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
//                        if (type==MESSAGE_TOAST){
//                            finish();
//                        }else if(type==MESSAGE_UP){
//                            check();
//                        }
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
    private void worningAlert(String msg, final int t) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示信息")
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton("確認", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
                        if (t==Constants.MESSAGE_TOAST) {
                            finish();
                        }
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
    //獲取院校線別
    private void getSchool(){
        showDialog();
        new Thread() {
            @Override
            public void run() {
                String url2 = Constants.HTTP_RZXQ_SCHOLL + "?window_code=" + FoxContext.getInstance().getLoginId();


                Log.e("---------", "url2==fff===" + url2);
                //把网络访问的代码放在这里
                String result = HttpUtils.queryStringForPost(url2);
                dismissDialog();
                Gson gson = new Gson();
                if (result != null) {
                    Log.e("---------", "result==fff===" + result);
                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        JsonArray array = jsonObject.get("data").getAsJsonArray();
                        if (!(array.size()>0))
                        {Log.e("-----------", "result==" + result);
                            Message message = new Message();
                            message.what = MESSAGE_NO_SCHOOL;
                            message.obj = "用戶無學校資料，請找管理員確認！";
                            mHandler.sendMessage(message);
                        }else {

                        schoolLost = new ArrayList<JVSchoolInfo>();

                        for (JsonElement type : array) {
                            JVSchoolInfo humi = gson.fromJson(type, JVSchoolInfo.class);
                            schoolLost.add(humi);
                        }
                            Message message = new Message();
                            message.what = MESSAGE_SET_SCHOOL;
                            message.obj = jsonObject.get("errMessage").getAsString();
                            mHandler.sendMessage(message);
                        }

                    } else {
                        Log.e("-----------", "result==" + result);
                        Message message = new Message();
                        message.what = MESSAGE_TOAST;
                        message.obj = "用戶無學校資料，請找管理員確認！";
                        mHandler.sendMessage(message);
                    }
                } else {
                    Message message = new Message();
                    message.what = MESSAGE_NETMISTAKE;
                    mHandler.sendMessage(message);
                    finish();
                }
            }
        }.start();
    }

    //基本信息下拉   傳值：flag DB
    private void getInfoBD(String flag){
        new Thread() {
            @Override
            public void run() {
                String url2 = Constants.HTTP_RZXQ_GET_INFO + "?flag=" + flag;

                Log.e("---------", "url2==fff===" + url2);
                //把网络访问的代码放在这里
                String result = HttpUtils.queryStringForPost(url2);
                dismissDialog();
                Gson gson = new Gson();
                if (result != null) {
                    Log.e("---------", "result==fff===" + result);
                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        JsonArray array = jsonObject.get("data").getAsJsonArray();
                        bdList = new ArrayList<JVSchoolInfo>();

                        for (JsonElement type : array) {
                            JVSchoolInfo humi = gson.fromJson(type, JVSchoolInfo.class);
                            bdList.add(humi);
                        }
                        Message message = new Message();
                        message.what = MESSAGE_SET_BD;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    }
                } else {
                    Message message = new Message();
                    message.what = MESSAGE_NETMISTAKE;
                    mHandler.sendMessage(message);
                    finish();
                }
            }
        }.start();
    }
private void setBD(){
        List<String> bdName=new ArrayList<>();
        for (int i = 0;i<bdList.size();i++){
            bdName.add(bdList.get(i).getNAME());
        }
    //稽核課隊下拉列表選擇
    spPlan.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, bdName));
    spPlan.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String str = bdName.get(position);
            way=bdName.get(position);
            Log.e("---------", "最喜欢的水果是：" + str);
//            paramMap.put("kedui",str);
        }
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
    //基本信息下拉   傳值：flag ZS
    private void getInfoZS(String flag){
        new Thread() {
            @Override
            public void run() {
                String url2 = Constants.HTTP_RZXQ_GET_INFO + "?flag=" + flag;

                Log.e("---------", "url2==fff===" + url2);
                //把网络访问的代码放在这里
                String result = HttpUtils.queryStringForPost(url2);
                dismissDialog();
                Gson gson = new Gson();
                if (result != null) {
                    Log.e("---------", "result==fff===" + result);
                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        JsonArray array = jsonObject.get("data").getAsJsonArray();
                        zsList = new ArrayList<JVSchoolInfo>();

                        for (JsonElement type : array) {
                            JVSchoolInfo humi = gson.fromJson(type, JVSchoolInfo.class);
                            zsList.add(humi);
                        }
                        Message message = new Message();
                        message.what = MESSAGE_SET_ZS;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    }
                } else {
                    Message message = new Message();
                    message.what = MESSAGE_NETMISTAKE;
                    mHandler.sendMessage(message);
                    finish();
                }
            }
        }.start();
    }

    private void setZS(){
        List<String> zsName=new ArrayList<>();
        for (int i = 0;i<zsList.size();i++){
            zsName.add(zsList.get(i).getNAME());
        }
        //稽核課隊下拉列表選擇
        spLive.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, zsName));
        spLive.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                 live = zsName.get(position);
//            paramMap.put("kedui",str);
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
    }
    //獲取接待人姓名
    private void getPeopleById(String id){
        showDialog();
        final String url = Constants.HTTP_COMMON_FORMS_SERVLET+"?code="+id;

        new Thread() {
            @Override
            public void run() {
                //把网络访问的代码放在这里
                String result = HttpUtils.queryStringForPost(url);

                dismissDialog();
                Log.e("---------", "==fff===" + url);
                Gson gson = new Gson();
                if (result != null) {
                    Log.e("---------", "result==fff===" + result);

                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        JsonArray array = jsonObject.get("data").getAsJsonArray();
                        empMessagesList = new ArrayList<EmpMessage>();

                        for (JsonElement type : array) {
                            EmpMessage humi = gson.fromJson(type, EmpMessage.class);
                            empMessagesList.add(humi);
                        }
                        Message message = new Message();
                        message.what = MESSAGE_SET_GET;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);
                    } else{
                        Message message = new Message();
                        message.what = MESSAGE_TOAST;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);
                    }
                }
            } }.start();
    }

    private int year, month, day;
    private void initDateTime() {
        Calendar calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH) ;
        day = calendar.get(Calendar.DAY_OF_MONTH);
    }
    private StringBuffer date, time;
    private void show(String from){
        AlertDialog.Builder builder = new AlertDialog.Builder(SchoolReleaseActivity.this);
        builder.setPositiveButton("设置", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (date.length() > 0) { //清除上次记录的日期
                    date.delete(0, date.length());
                    Log.e("--------","date.length()==="+date.length());
                }
                if (from.equals("start")) {
                    tvDateCome.setText(date.append(String.valueOf(year)).append("-").append(String.valueOf(month+1)).append("-").append(day));
                    tvAllTime.setText(""+TimeDateUtils.daysDeviationDate(tvDateCome.getText().toString(),tvDateReturn.getText().toString()));
                }else{
                    tvDateReturn.setText(date.append(String.valueOf(year)).append("-").append(String.valueOf(month+1)).append("-").append(day ));
                    tvAllTime.setText(""+TimeDateUtils.daysDeviationDate(tvDateCome.getText().toString(),tvDateReturn.getText().toString()));
                }
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        final AlertDialog dialog = builder.create();
        View dialogView = View.inflate(SchoolReleaseActivity.this, R.layout.dialog_date, null);
        final DatePicker datePicker = (DatePicker) dialogView.findViewById(R.id.datePicker);
        dialog.setTitle("設置日期");
        dialog.setView(dialogView);
        dialog.show();
        //初始化日期监听事件
        datePicker.init(year, month, day, this);
    }
    @Override
    public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        this.year = year;
        this.month = monthOfYear;
        this.day = dayOfMonth;

    }
}
